// remove tags
function stripHtmlTags(s,max){
s=s.replace(/<br.*?>/ig, ' ');
return s.replace(/<.*?>/ig, '').split(/\s+/).slice(0,max-1).join(' ')
}

numposts = 40; 
//get RSS FEED
function showrecentposts(json) {

	img  = new Array();
    if (numposts <= json.feed.entry.length) {
		maxpost = numposts;
		}
	else
       {
	   maxpost=json.feed.entry.length;
	   }
	   
for (var i = 0; i < maxpost; i++) {

	//Get Entry
	var entry = json.feed.entry[i];
	var posttitle = entry.title.$t;
	var pcm ;
	var posturl;
	
	//Get Image Thumb
	if("media$thumbnail" in entry){
	var thumburl = entry.media$thumbnail.url;
	}
	else{ var thumburl = "http://lh6.googleusercontent.com/-8fE2X7kBhWs/Tf96WzivFHI/AAAAAAAAB0s/fItUKGW08gY/no-image.png"};
	
	if (i == json.feed.entry.length) break;
	
	//Get link Url
	for (var k = 0; k < entry.link.length; k++) {
		if (entry.link[k].rel == 'alternate') {
		posturl = entry.link[k].href;
			break;
		}
	}	
	
	//Get Label
	var plabel = new Array();
	var cate = entry.category;
	if(cate) {
		for (var k = 0; k < entry.category.length; k++) {
			plabel[k] = ' <a class="label-link" href="http://www.maphim.net/search/label/'+entry.category[k].term+'">'+entry.category[k].term+'</a> ';
		}
	}
	else {plabel = "No label";}
	
	//Get body (Post)
	var authpost = entry.author[0].name.$t;
	var postdate = entry.published.$t;
	var month = [1,2,3,4,5,6,7,8,9,10,11,12];
	var month2 = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	var day = postdate.split("-")[2].substring(0,2);
	var m = postdate.split("-")[1];
	var y = postdate.split("-")[0];
	postDay = day+ "/" + m + "/" + y ;
	
		//Post Content
	if ("content" in entry) {
		var postcontent = entry.content.$t;}
	else if ("summary" in entry) {
		var postcontent = entry.summary.$t;}
	else postcontent = "";
	
	s = postcontent; a = s.indexOf("<img"); b = s.indexOf("src=\"",a); c = s.indexOf("\"",b+5); d = s.substr(b+5,c-b-5);
	
		//Post Image
	if((a!=-1)&&(b!=-1)&&(c!=-1)&&(d!="")) {img[i] = d;}
	else {img[i]="http://1.bp.blogspot.com/_u4gySN2ZgqE/SosvnavWq0I/AAAAAAAAArk/yL95WlyTqr0/s400/noimage.png";}

	
	//Data show for view.
	
	var td_list = '<div class="hover card index">' 
				+ '<div class="front bgcl">'
				+ '<a href="'+posturl+'" title="'+posttitle+'" rel="'+posttitle+'">'
				+ '<img class="vItemThumb" src="'+img[i]+'" alt="'+posttitle+'" /></a>'
				+ '<h6>'+posttitle+'</h6>'
				+ '<span class="bgcl">'
				+ '<a class="more" title="Nghe tôi kể..." href="'+posturl+'">Nghe tôi kể...</a></span>'
				+ '</div>'
				+ '<div class="back card bgcl">'
				+ '<div class="pad"><h6>'+posttitle+'</h6>'
				+ '<p style="margin:5px;overflow: hidden;bottom:2px;height:195px">'+stripHtmlTags(postcontent,58)+'...</p>'
				+ '<span class="bgcl">'
				+ '<a class="more" title="Nghe tôi kể..." href="'+posturl+'">Nghe tôi kể...</a></span>'
				+ '</div></div>'
				+ '</div>';
	
		//Check view --
	document.write(td_list);
		
	} //End for

}	//End function